<?php
include_once("Class.php");

class Character
{
	// Default fields -- always available
	public $id 				= -1;
	public $key				= "";
	public $genderId		= -1;
	public $raceId 			= -1;
	public $birthsignId 	= -1;
	
	// Class definition
	public $classId			= -1;
	public $customClassId	= -1;
	public $customClass 	= null;
	
	// Sets
	public $skillSet		= null;
	public $attributeSet 	= null;
	
	function __construct($id, $genderId, $raceId, $birthsignId, $classId, $customClassId)
	{
		$this->id = $id;
		$this->genderId = $genderId;
		$this->raceId = $raceId;
		$this->birthsignId = $birthsignId;
		$this->classId = $classId;
		$this->customClassId = $customClassId;
	}
	
	public static function ConstructFromRow($row)
	{
		// Read the data from the row
		$id = $row["id"];
		$genderId = $row["gender_id"];
		$raceId = $row["race_id"];
		$birthsignId = $row["birthsign_id"];
		$classId = $row["class_id"];
		$customClassId = $row["custom_class_id"];
		
		// Construct the new Character
		return new Character($id, $genderId, $raceId, $birthsignId, $classId, $customClassId);
	}
	
	public function ToArray()
	{
		$array = array(
			"id" => $this->id,
			"key" => $this->key,
			"gender" => $this->genderId,
			"race" => $this->raceId,
			"birthsign" => $this->birthsignId,
			"class" => $this->classId,
			"customClassId" => $this->customClassId,
			"customClass" => $this->customClass != null ? $this->customClass->ToArray() : null,
			"skillSet" => $this->skillSet != null ? $this->skillSet->skills : null,
			"attributeSet" => $this->attributeSet != null ? $this->attributeSet->attributes : null,
		);
		return $array;
	}
	
	public function ToString()
	{
		// General Character information
		$returnString = "ID: " .$this->id
			.", genderId: " .$this->genderId .", raceId: " .$this->raceId
			.", birthsignId: ".$this->birthsignId;
			
		// Class ToString
		if($this->customClass != null)
			$returnString .= "\n\nClass: \n" .$this->customClass->ToString();
		else
			$returnString .= "\n\nClassId: " .$this->classId;
		
		// SkillSet ToString
		if($this->skillSet != null)
			$returnString .= "\n\n---SkillSet---" .$this->skillSet->ToString();
			
		// AttributeSet ToString
		if($this->attributeSet != null)
			$returnString .= "\n\n---AttributeSet---" .$this->attributeSet->ToString();
		
		return $returnString;
	}
}
?>